<%-- 
    Document   : view
    Created on : Mar 8, 2010, 10:49:03 AM
    Author     : Jagadeesh
--%>
<html xmlns="http://www.w3.org/1999/xhtml">
    <%@page import="database.DBClass"%>
    <%@page import="validation.ValidateForm"%>
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    <%@page import="java.util.*,java.io.*" %>
    <%@page import="model.UserBean" %>
    <%

        if (session.getAttribute("user") == null) {

            RequestDispatcher rd = request.getRequestDispatcher("login.jsp");
            rd.forward(request, response);
        }

    %>
    <html>
        <head>
            <meta charset="utf-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <meta name="description" content="">
            <meta name="author" content="">

            <title>Information System Medcine</title>

            <!-- Bootstrap core CSS -->
            <link href="css/bootstrap.css" rel="stylesheet">

            <!-- Custom CSS for the '3 Col Portfolio' Template -->
            <link href="css/3-col-portfolio.css" rel="stylesheet">
        </head>
        <body>
        <nav class="navbar navbar-fixed-top navbar-inverse" role="navigation">
            <div class="container">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand">ISMED</a>
                </div>

                <!-- Collect the nav links, forms, and other content for toggling -->
                <div class="collapse navbar-collapse navbar-ex1-collapse">
                    <ul class="nav navbar-nav">
                        <li><a href="index.jsp">Pencarian Obat</a></li>
                        <li><a href="#services">Pencarian Apotek</a></li>
                     <li><a href="login.jsp">Login Admin</a></li>

                    </ul>
                </div><!-- /.navbar-collapse -->
            </div><!-- /.container -->
        </nav>

        <div class="container">

            <div class="row">

                <div class="col-lg-12">
                    <h1 class="page-header">Insert Update Admin </h1>
                </div>

                <form method="link" action="logout.jsp">
                    <input type="submit" value="Logout"/>
                </form>
                <form method="link" action="insertupdate.jsp">
                    <input type="submit" value="Insert Admin"/>
                </form>
                <table width="100%"border="1" class="table table-striped">
                    <tr>
                        <th>Username</th>
                        <th>Nama Admin</th>
                        <th>Action</th>
                    </tr>
                    <%
                        UserBean bean = new UserBean();
                        // ValidateForm validateform = new ValidateForm();
                        DBClass dbobject = new DBClass();

                        if (!session.getAttribute("user").equals("admin")) {
                            //
                            //                    RequestDispatcher rd = request.getRequestDispatcher("login.jsp");
                            //                    rd.forward(request, response);
                            dbobject.insertDetails(bean);
                            List list = dbobject.getAlldetails();
                            request.setAttribute("list", list);
                            List list2 = (List) request.getAttribute("list");
                            if (list2 != null) {
                                for (int i = 0; i < list2.size(); i++) {
                                    UserBean ubean = (UserBean) list2.get(i);
                    %>
                    <tr>
                        <td><%=ubean.getUserName()%></td>
                        <td><%=ubean.getEmail()%></td>

                    </tr>
                    <%
                            }
                        }
                    } else {
                        //dbobject.insertDetails(bean);
                        List list3 = dbobject.getAlldetails();
                        request.setAttribute("list", list3);
                        List list4 = (List) request.getAttribute("list");
                        if (list4 != null) {
                            for (int i = 0; i < list4.size(); i++) {
                                UserBean ubean = (UserBean) list4.get(i);

                    %>
                    <tr>
                        <td><%=ubean.getUserName()%></td>
                        <td><%=ubean.getEmail()%></td>
                        <td><a href="ControllerServlet?action=edit&userName=<%=ubean.getUserName()%>">update</a>
                            |
                            <a href="ControllerServlet?action=delete&userName=<%=ubean.getUserName()%>">delete</a>
                    </tr>
                    <%
                                }
                            }
                        }
                    %>
                </table>




                </body>
                </html>